package com.qixin.total.controller;

import com.alibaba.fastjson.JSONObject;
import com.qixin.api.bean.ComCar;
import com.qixin.api.bean.ComPeople;
import com.qixin.api.bean.ResultPage;
import com.qixin.api.bean.VoPage;
import com.qixin.api.service.ComCarService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;

/**
 * 李许多
 * 车辆管理
 * Created by aa on 2018/11/1.
 */
@Controller
@RequestMapping("/caradmin")
public class CaradminController {
    private static final Logger logger = LoggerFactory.getLogger(CaradminController.class);
    @Autowired
    ComCarService comCarService;
    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("/main.html")
    public String car(){
        return "pingtai/caradmin";

    }
    //查询
    @RequestMapping("/select")
    @ResponseBody
    public ResultPage<ComCar> list(VoPage voPage) {
        ResultPage<ComCar> resultPage=comCarService.selectcar(voPage);
        return  resultPage;
    }
//取到图片方法
    @RequestMapping("/getPhoto")
    public   void getPhoto(HttpServletResponse response,@RequestParam("path") String path) throws Exception {
        File file = new File(path);
        FileInputStream fis; fis = new FileInputStream(file);
        long size = file.length();
        byte[] temp = new byte[(int) size];
        fis.read(temp, 0, (int) size);
        fis.close();
        byte[] data = temp;
        response.setContentType("image/png");
        OutputStream out = response.getOutputStream();
        out.write(data);
        out.flush();
        out.close();
    }
    /**
     * 传参
     * @param
     * @return
     */
    @RequestMapping("/check.html")
    public String check(String url,Model model){
        model.addAttribute("url",url);
        return "/pingtai/carcheck";

    }
    /**
     * 修改
     * @param param
     * @return
     */
    @RequestMapping("/updatecheck")
    @ResponseBody
    public  boolean updatecheck(String param){
        ComCar comCar  = JSONObject.parseObject(param, ComCar.class);
        if(comCarService.updateById(comCar)){
            return  true;
        }else{
            return false;
        }
    }
    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("/detail.html")
    public String detail(){
        return "pingtai/cardetail";

    }
}
